package com.vm.osm.business.service.omp.impl;

import com.vm.osm.business.dto.omp.industry.OmpIndustry;
import com.vm.osm.business.dto.omp.type_dicts.TypeDict;
import com.vm.osm.business.service.omp.IOmpIndustryService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import java.util.Arrays;
import java.util.List;

@Service
public class OmpIndustryServiceImpl implements IOmpIndustryService {
    private static final Logger LOG = LoggerFactory.getLogger(OmpIndustryServiceImpl.class);
    @Value("${omp_api_url}")
    private String OMP_API_URL;
    @Autowired
    private RestTemplate restTemplate;

    @Override
    public List<OmpIndustry> list() {
        try {
            LOG.info("【行业】（获取行业列表）");
            String URL = OMP_API_URL + "/omp/v1.0/industrys";
            ResponseEntity<OmpIndustry[]> entity = restTemplate.getForEntity(URL, OmpIndustry[].class);
            return Arrays.asList(entity.getBody());
        } catch (Exception e) {
            LOG.error("【行业】（获取行业列表）异常", e);
            return null;
        }
    }
}
